package com.intsig.airflow.web.model;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 描述DAG中节点的数据模型
 *
 * @author leojie 2021/3/13 1:55 下午
 */
public class DagNode {
    public static final String ID = "id";
    public static final String NAME="name";
    public static final String IN_PORTS="in_ports";
    public static final String OUT_PORTS="out_ports";
    public static final String WIDTH = "width";
    public static final String HEIGHT = "height";
    public static final String POS_X="pos_x";
    public static final String POS_Y="pos_y";
    public static final String TYPE="type";
    public static final String DEFAULT_TYPE_VALUE = "Variable";
    public static final String RIGHT_CLICK_EVENT="rightClickEvent";
    public static final String RIGHT_CLICK_EVENT_LABEL = "label";
    public static final String RIGHT_CLICK_EVENT_NAME = "eventName";
    public static final String NODE_STYLE = "nodeStyle";


    private Long id;
    /**
     * 节点名称，对应着task 名称
     */
    private String name;
    private Integer width;
    private Integer height;
    private Float posX;
    private Float posY;
    private int[] inPorts;
    private int[] outPorts;
    /**
     * 节点类型
     */
    private String type;
    /**
     * 节点样式
     */
    private Map<String, String> nodeStyle;

    /**
     * 节点对应的右键事件
     */
    private List<NodeRightClickEvent> rightClickEvent;

    static class NodeRightClickEvent {
        private String label;
        private String eventName;

        public String getLabel() {
            return label;
        }

        public void setLabel(String label) {
            this.label = label;
        }

        public String getEventName() {
            return eventName;
        }

        public void setEventName(String eventName) {
            this.eventName = eventName;
        }
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getWidth() {
        return width;
    }

    public void setWidth(Integer width) {
        this.width = width;
    }

    public Integer getHeight() {
        return height;
    }

    public void setHeight(Integer height) {
        this.height = height;
    }

    public Float getPosX() {
        return posX;
    }

    public void setPosX(Float posX) {
        this.posX = posX;
    }

    public Float getPosY() {
        return posY;
    }

    public void setPosY(Float posY) {
        this.posY = posY;
    }

    public int[] getInPorts() {
        return inPorts;
    }

    public void setInPorts(int[] inPorts) {
        this.inPorts = inPorts;
    }

    public int[] getOutPorts() {
        return outPorts;
    }

    public void setOutPorts(int[] outPorts) {
        this.outPorts = outPorts;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public Map<String, String> getNodeStyle() {
        return nodeStyle;
    }

    public void setNodeStyle(Map<String, String> nodeStyle) {
        this.nodeStyle = nodeStyle;
    }

    public void setNodeStyle(String styleName, String styleValue){
        if(this.nodeStyle == null){
            this.nodeStyle = new HashMap<>();
        }
        this.nodeStyle.put(styleName, styleValue);
    }

    public List<NodeRightClickEvent> getRightClickEvent() {
        return rightClickEvent;
    }

    public void setRightClickEvent(List<NodeRightClickEvent> rightClickEvent) {
        this.rightClickEvent = rightClickEvent;
    }

    public void addNodeRightClickEvent(String label, String eventName){
        if(this.rightClickEvent == null){
            this.rightClickEvent = new ArrayList<>();
        }
        NodeRightClickEvent clickEvent = new NodeRightClickEvent();
        clickEvent.setLabel(label);
        clickEvent.setEventName(eventName);
        this.rightClickEvent.add(clickEvent);
    }

}


